﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SeaBlueU5.Web.Standard
{

    public partial class Login : System.Web.UI.Page
    {
        public string msg = "";
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Request.HttpMethod.ToLower() == "post")
            {
                if (!string.IsNullOrEmpty(Request.Form["username"]) && !string.IsNullOrEmpty(Request.Form["pwd"]))
                {
                    string username = Request.Form["username"].ToString().Trim();
                    string pwd = Request.Form["pwd"].ToString().Trim();
                    //pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5");
                    SeaBlueU5.BLL.User userbll = new SeaBlueU5.BLL.User();
                    SeaBlueU5.Model.Standard.User user = userbll.GetModel(username);
                    if (user != null && user.UPwd == pwd)
                    {
                        user.CTime = DateTime.Now;
                        userbll.Update(user);
                        Session["user"] = user;
                        Response.Cookies.Add(new HttpCookie("username", user.UName));
                        if (Request.Form["remember"] == "on")
                        {
                            Response.Cookies["username"].Expires = DateTime.Now.AddDays(30);
                        }
                        if (Request.QueryString["url"] != null)
                        {
                            Response.Redirect(Request.QueryString["url"]);
                        }
                        Response.Redirect("Default.aspx");
                    }
                    else
                    {
                        msg = "用户名或密码错误！";
                    }
                }
                else
                {
                    msg = "用户名或密码不能为空！";
                }
            }
        }
    }
}